cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA4.log", replace

clear all
set more off

matrix Results = J(48, 10, 0)

use "RawData/GallupDataBJPS.dta", clear
// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Party")
// Drops Obs. w/o Party ID
drop if party == -9 | party == -99

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
gen quarter = qofd(middle_date)
format quarter %tq

levelsof quarter, local (fourths) 

foreach i of local fourths {
local counter = `i' + 28
local year = 1953 + floor(`counter' / 4)
tab series if quarter == `i'
local row = 1 + mod(`counter', 4)*2 + floor((`year' - 1953) / 10)*8
local column = 1 + mod((`year' - 1953), 10)
matrix Results[`row', `column'] = r(N)
matrix Results[`row'+1, `column'] = -r(r)
}

matlist Results

log close
